/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package extension.room.tan;

import extension.tan.handler.TanFlag;
import extension.tan.handler.TanCommand;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import extension.game.room.GameResponse;
import java.util.LinkedList;
import java.util.List;
import log.Debug;

/**
 *
 * @author daz
 */
public class TanResponse extends GameResponse {

    public TanResponse(TanExtension ext) {
        super(ext);
    }

    void sendDealCard(List<Integer> listCards, List<Integer> listPhom, User user) {
        ISFSObject resObj = new SFSObject();
        ext.send(TanCommand.DEAL_CARD, resObj, user);
    }

    void sendFirstTurn(int gameTurn, List<User> userList) {
        ISFSObject resObj = new SFSObject();
        ext.send(TanCommand.FIRST_TURN, resObj, userList);
        log(resObj);
    }

    public void sendFightCard(int canFight, int playerFight, User user) {
        ISFSObject resObj = new SFSObject();
        ext.send(TanCommand.FIGHT_CARD, resObj, user);
        log(resObj);
    }

    public void sendFightCard(int cardSend, int canFight, int gameTurn, List<User> listSend) {
        ISFSObject resObj = new SFSObject();
        List<Integer> listCardFights = new LinkedList<Integer>();
        listCardFights.add(cardSend);
        resObj.putIntArray(TanFlag.CARD_FIGHT, listCardFights);
        resObj.putInt(TanFlag.PLAYER_FIGHT, gameTurn);
        resObj.putInt(TanFlag.CAN_FIGHT, canFight);
        ext.send(TanCommand.FIGHT_CARD, resObj, listSend);
        log(resObj);
    }

    public void sendFightCard(int canFight, User user) {
        ISFSObject resObj = new SFSObject();
        resObj.putInt(TanFlag.CAN_FIGHT, canFight);
        ext.send(TanCommand.FIGHT_CARD, resObj, user);
        log(resObj);
    }

    void sendMoneyChange(long moneyChange, int playerWin, long playerWinMoney, int playerLost, long playerLostMoney) {
        ISFSObject resObj = new SFSObject();
        resObj.putLong(TanFlag.MONEY_CHANGE, moneyChange);
        resObj.putInt(TanFlag.PLAYER_WIN, playerWin);
        resObj.putLong(TanFlag.PLAYER_WIN_MONEY, playerWinMoney);
        resObj.putInt(TanFlag.PLAYER_LOST, playerLost);
        resObj.putLong(TanFlag.PLAYER_LOST_MONEY, playerLostMoney);
        ext.send(TanCommand.MONEY_CHANGE, resObj, ext.getParentRoom().getUserList());
    }

    void sendUpdateTableHost(int newTableHost, int isPlay) {
        Debug.d("send update table host");
        ISFSObject resObj = new SFSObject();
        resObj.putInt(TanFlag.TABLE_HOST, newTableHost);
        resObj.putInt(TanFlag.IS_PLAY, isPlay);
        ext.send(TanCommand.UPDATE_TABLE_HOST, resObj, ext.getParentRoom().getUserList());
    }

    void sendDealCard(List<Integer> listCards, User user) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putIntArray(TanFlag.LIST_CARDS, listCards);
        ext.send(TanCommand.DEAL_CARD, resObj, user);
        log(resObj);
    }

    void sendFirstTurn(int gameTurn, int defenseTurn, int lastBlock, List<User> userList) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(TanFlag.DEFENSE_TURN, defenseTurn);
        resObj.putInt(TanFlag.FIRST_TURN, gameTurn);
        resObj.putInt(TanFlag.LAST_BLOCK, lastBlock);
        ext.send(TanCommand.FIRST_TURN, resObj, userList);
        log(resObj);
    }

    public void sendFightAll(int rank, int seatPos, int numberViews) {
        ISFSObject resObj = new SFSObject();
        resObj.putInt(TanFlag.PLAYER_RANK, rank);
        resObj.putInt(TanFlag.PLAYER_FINISH, seatPos);
        resObj.putInt(TanFlag.NUMBER_VIEW, numberViews);
        ext.send(TanCommand.FIGHT_ALL, resObj, ext.getParentRoom().getUserList());
    }

    void sendGameTurn(int gameTurn, int attatckTurn, int defenseTurn, int lastBlock, List<Integer> listBlock, int finishRound, List<Integer> listRegister) {
        ISFSObject resObj = new SFSObject();
        resObj.putInt(TanFlag.DEFENSE_TURN, defenseTurn);
        resObj.putInt(TanFlag.GAME_TURN, gameTurn);
        resObj.putInt(TanFlag.LAST_BLOCK, lastBlock);
        resObj.putInt(TanFlag.FINISH_ROUND, finishRound);
        resObj.putInt("attack_turn", attatckTurn);
        resObj.putIntArray("suggest_card", listBlock);
        resObj.putIntArray("list_register", listRegister);
        ext.send(TanCommand.GAME_TURN, resObj, ext.getParentRoom().getUserList());
        log(resObj);
    }

    void sendFinishMatch(List<Long> moneyResult, List<Long> playerMoney, int playerWin, int tableHost, int numberPlayers) {
        ISFSObject resObj = new SFSObject();
        resObj.putLongArray(TanFlag.MONEY_RESULT, moneyResult);
        resObj.putLongArray(TanFlag.PLAYER_MONEY, playerMoney);
        resObj.putInt(TanFlag.PLAYER_WIN, playerWin);
        resObj.putInt(TanFlag.TABLE_HOST, tableHost);
        resObj.putInt(TanFlag.NUMBER_PLAYERS, numberPlayers);
        ext.send(TanCommand.FINISH_MATCH, resObj, ext.getParentRoom().getUserList());
    }

    void sendAskRegisterAttack(User user) {
        ext.send(TanCommand.ASK_REGISTER_ATTACK, null, user);
    }

    void sendFinishRound() {
        ext.send(TanCommand.NEW_ROUND, null, ext.getParentRoom().getUserList());
    }

    public void sendEnFoldCard(List<Integer> listCardOnTable, int enFoldPos, List<User> userList) {
        ISFSObject resObj = new SFSObject();
        resObj.putIntArray("list_cards", listCardOnTable);
        resObj.putInt("en_fold_pos", enFoldPos);
        ext.send(TanCommand.ENFOLD_CARD, resObj, userList);
    }

    void sendAdditonalCard(List<Integer> listAdditonalCard, User user) {
        ISFSObject resObj = new SFSObject();
        resObj.putIntArray("list_cards", listAdditonalCard);

        ext.send(TanCommand.ADDITIONAL_CARD, resObj, user);
    }

    void sendMasterCard(int firstTurn, int masterCard, List<User> userList) {
        ISFSObject resObj = new SFSObject();
        resObj.putInt("first_turn", firstTurn);
        resObj.putInt("master_card", masterCard);
        ext.send(TanCommand.CHOOSE_MASTER_CARD, resObj, userList);
    }

    void sendNumberCardRemain(int size, List<User> listUser) {
        ISFSObject resObj = new SFSObject();
        resObj.putInt("number_card_remain", size);
        ext.send(TanCommand.REMAIN_CARD, resObj, listUser);
    }

    void sendUpdateCardDown(List<Integer> listMissings, List<Integer> listNumberCardInHand, List<User> listUser) {
        ISFSObject resObj = new SFSObject();
        resObj.putIntArray("number_card_in_hand", listNumberCardInHand);
        resObj.putIntArray("number_card_addition", listMissings);
        ext.send(TanCommand.UPDATE_CARD_DOWN, resObj, listUser);
    }
}
